/**
 * Copyright (c) 2011 eelpo.com
 * All rights reserved.
 */
package com.eelpo.cmmp.core.wicket.panel.grid.column;

import org.apache.wicket.Component;
import org.apache.wicket.markup.html.list.Loop;
import org.apache.wicket.markup.html.list.Loop.LoopItem;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;

/**
 * <pre>
 * 
 * 一个操作的列
 * 
 * </pre>
 * 
 * @author <a href="mailto:Brian@eelpo.com">汪洪州</a>
 * @since 1.0
 */
public abstract class OperatePanel<T> extends Panel {

	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 4489222603743928772L;

	/**
	 * 上一个链接是否显示
	 */
	private boolean previousVisible = false;

	/**
	 * @param id
	 */
	public OperatePanel(String id, int iterations, IModel<T> model) {
		super(id);

		add(loop(iterations, model));
	}

	public Component loop(final int iterations, final IModel<T> model) {

		return new Loop("loop", iterations) {

			private static final long serialVersionUID = -1342969120024855326L;

			@Override
			protected void populateItem(LoopItem item) {
				OperatePanel.this.populateItem("link", "span", item, model);
			}

			@Override
			protected void renderItem(LoopItem item) {

				if (previousVisible && item.get(0).isVisible()) {
					getResponse().write(" / ");
				}

				previousVisible = item.get(0).isVisible();

				super.renderItem(item);
			}

		}.setRenderBodyOnly(true);
	}

	public abstract void populateItem(String id, String labelId, LoopItem item, IModel<T> model);
}
